package cac.fenjian.resource.system.controller;

import cac.fenjian.resource.system.service.SystemQueryService;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
@RequestMapping("system/query")
@RestController
public class SystemQueryController {
    @Autowired
    private SystemQueryService systemQueryService;

    //查询菜单
    @PostMapping("queryMenu")
    public List<HashMap> queryMenu(@RequestBody HashMap para){
        return systemQueryService.queryMenu(para);
    }
    //查询菜单树
    @PostMapping("queryMenuTree")
    public List<HashMap> queryMenuTree(){
        return systemQueryService.queryMenuTree();
    }

    //查询角色列表
    @PostMapping("queryRole")
    public PageInfo queryRole(@RequestBody HashMap para){
        int pageNum = Integer.parseInt(para.get("curPageNum").toString());
        int pageSize = Integer.parseInt(para.get("pageSize").toString());
        PageHelper.startPage(pageNum,pageSize);
        List<HashMap> list = systemQueryService.queryRole(para);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }
    //查询用户
    @PostMapping("searchUser")
    public PageInfo searchUser(@RequestBody HashMap para){
        String text = (String)para.get("text");
        int pageNum = Integer.parseInt(para.get("curPageNum").toString());
        int pageSize = Integer.parseInt(para.get("pageSize").toString());
        PageHelper.startPage(pageNum,pageSize);
        List<HashMap> list = systemQueryService.searchUser(text);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }
    //查询角色菜单
    @PostMapping("queryRoleMenus")
    public List<String> queryRoleMenus(@RequestBody HashMap map){
        return systemQueryService.queryRoleMenus((String)map.get("tsRoleId"));
    }

    @PostMapping("queryUserDetailPage")
    public PageInfo queryUserDetailPage(@RequestBody HashMap para){
        int pageNum = Integer.parseInt(para.get("curPageNum").toString());
        int pageSize = Integer.parseInt(para.get("pageSize").toString());
        PageHelper.startPage(pageNum,pageSize);
        List<HashMap> list = systemQueryService.queryUserDetail(para);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }
    @PostMapping("queryUserDetail")
    public List<HashMap> queryUserDetail(@RequestBody HashMap para){
        List<HashMap> list = systemQueryService.queryUserDetail(para);
        return list;
    }
}
